import java.io.*;
import java.util.*;

public class Main {
	BufferedReader bf;
	StringTokenizer st;
	StringBuilder sb;
	
	int n;
	String str;
	
	public Main() {
		bf = new BufferedReader(new InputStreamReader(System.in));
		sb = new StringBuilder();
	}
	
	public static void main(String[] args) {
		Main main = new Main();
		main.beginProcess();
	}

	public void beginProcess() {
		try {
			int i;
			
			st = new StringTokenizer(bf.readLine());
			n = Integer.parseInt(st.nextToken());
			
			for(i = 0; i < n; i++) {
				st = new StringTokenizer(bf.readLine());
				str = st.nextToken();
				sb.append(getReverse());
			}

			System.out.print(sb);
		}
		catch(Exception ex) {
			System.err.println(ex.toString());
		}
	}
	
	private String getReverse() {
		int i;
		char tmp;
		String result = "";
		Stack<Character> stack = new Stack<Character>();
		
		for(i = 0; i < str.length(); i++) {
			tmp = str.charAt(i);
			if(tmp >= 'A' && tmp <= 'Z') {
				tmp += 32;
				stack.push(tmp);
				continue;
			}
			else if(tmp >= 'a' && tmp <= 'z') {
				tmp -= 32;
				stack.push(tmp);
				continue;
			}
			else {
				stack.push(tmp);
				continue;
			}
		}
		
		while(!stack.isEmpty())
			result += stack.pop();
		
		return result + "\n";
	}
	
}